package com.imooc.infra.repository.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.imooc.infra.repository.entity.TDataCenterRule;
import com.imooc.infra.repository.mapper.TDataCenterRuleMapper;
import com.imooc.infra.repository.service.ITDataCenterRuleService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 18870
 * @since 2023-05-27
 */
@Service
public class TDataCenterRuleServiceImpl extends ServiceImpl<TDataCenterRuleMapper, TDataCenterRule> implements ITDataCenterRuleService {

    @Override
    public TDataCenterRule getByBusinessIdAndRuleType(String businessId, String ruleType) {
        LambdaQueryWrapper<TDataCenterRule> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(TDataCenterRule::getBusinessId, businessId);
        wrapper.eq(TDataCenterRule::getRuleType, ruleType);
        wrapper.orderByDesc(TDataCenterRule::getGmtCreate);

        return this.defaultGetOne(wrapper);
    }

    @Override
    public List<String> listBusinessIds() {
        return baseMapper.queryBusinessIds();
    }

    @Override
    public List<TDataCenterRule> listAll() {
        return this.list();
    }
}
